/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.cip.esymons.colegiatura.beans;

import java.util.List;
import javax.faces.model.SelectItem;
import org.cip.esymons.colegiatura.bc.PersonaJuridicaDelegate;
import org.cip.esymons.general.be.PersonaJuridica;

/**
 *
 * @author ADMINISTRADOR
 */
public class personaJuridicaController {

    private PersonaJuridicaDelegate delegado;
    private PersonaJuridica perJuridica;

    public personaJuridicaController() {

        delegado = new PersonaJuridicaDelegate();
        perJuridica = new PersonaJuridica();
    }

    public PersonaJuridicaDelegate getDelegado() {
        return delegado;
    }

    public void setDelegado(PersonaJuridicaDelegate delegado) {
        this.delegado = delegado;
    }

    public PersonaJuridica getPerJuridica() {
        return perJuridica;
    }

    public void setPerJuridica(PersonaJuridica perJuridica) {
        this.perJuridica = perJuridica;
    }

    public PersonaJuridica buscarPorCodigo(Long codigo){

        return delegado.find(codigo);
    }

    public List<PersonaJuridica> listaPerJuridica(){

        return delegado.findAll();
    }

    public SelectItem[] getSelectListaEmpresa(){

      try{
//        System.out.println("Ingreso 1");
        SelectItem[] selects = null;
        List<PersonaJuridica> listaperJur = delegado.findAll();
        selects = new SelectItem[listaperJur.size()];
        int cont = 0;
        for(PersonaJuridica pj : listaperJur){

            SelectItem item = new SelectItem(pj, pj.getEmprazonSocial());
            selects[cont] = item;
            cont++;
        }
        return selects;
      }catch(Exception e){
            System.out.println("Ingreso Error");
            SelectItem[] selects = new SelectItem[1];
            SelectItem item = new SelectItem(null, "No existen empresas");
            selects[0] = item;
            return selects;
      }

    }

        public SelectItem[] getListaEmpresas(){

      try{
//        System.out.println("Ingreso 1");
        SelectItem[] selects = null;
        List<PersonaJuridica> listaperJur = delegado.findAll();
        selects = new SelectItem[listaperJur.size()];
        int cont = 0;
        for(PersonaJuridica pj : listaperJur){

            SelectItem item = new SelectItem(pj.getSolCodigo(), pj.getEmprazonSocial());
            selects[cont] = item;
            cont++;
        }
        return selects;
      }catch(Exception e){
            System.out.println("Ingreso Error");
            SelectItem[] selects = new SelectItem[1];
            SelectItem item = new SelectItem(null, "No existen empresas");
            selects[0] = item;
            return selects;
      }

    }


}
